package com.xhwl.centiotdata.pushtrigger.alarm.subscribe;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xhwl.centiotdata.pojo.constant.IVS1800Constant;
import com.xhwl.centiotdata.pojo.constant.IVS3800Constant;
import com.xhwl.centiotdata.utils.ThreadPoolUtils;
import com.xhwl.common.dto.cent.alarm.AlarmIntegrationConfigDTO;
import com.xhwl.centiotdata.pollingtrigger.ScheduleDispatcher;
import com.xhwl.centiotdata.service.integrateconfig.AlarmIntegrationConfig;
import com.xhwl.common.dto.cent.alarm.haiwei3800.*;
import com.xhwl.common.enums.ProductEnum;
import com.xhwl.common.exception.DataException;
import com.xhwl.common.utils.DateUtils;
import com.xhwl.common.utils.XMLUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
@Component
public class IVS3800Subscribe implements ScheduleDispatcher {

    @Autowired
    AlarmIntegrationConfig alarmIntegrationConfig;

    private static final List<AlarmIntegrationConfigDTO> integrationConfigList = new ArrayList<>();

    @Override
    public void doOneMinutesTask() {

    }

    @Override
    public void doTenMinutesTask () {
        ThreadPoolUtils.alarmExecutor.execute(this::getToken);
    }

    @Override
    public void doOneDayTask() {
        ThreadPoolUtils.alarmExecutor.execute(this::resetSubscribe);
    }

    @EventListener
    public void listenIntegrationConfig(AlarmIntegrationConfigEvent event) {
        ThreadPoolUtils.alarmExecutor.execute(this::getToken);
    }

    public void resetSubscribe() {
        for (AlarmIntegrationConfigDTO configDTO : integrationConfigList) {
            try {
                if (!StringUtils.isEmpty(configDTO.getToken())) {
                    log.info("===== ivs3800 重新订阅  {}", configDTO);
                    alarmSubscribe(configDTO);
                    intelligenceSubscribe(configDTO);
                } else {
                    log.error("ivs3800 告警重新订阅失败, token 不存在 {}", configDTO);
                }
            }
            catch (Exception e) {
                log.error("ivs3800 告警重新订阅失败 {}", e.getMessage());
            }
        }
    }

    private void getToken()  {
        syncConfig();
        for (AlarmIntegrationConfigDTO configDTO : integrationConfigList) {
            log.info("IVS 3800 开始 ===================: {}", configDTO);

            try {
                if (StringUtils.isEmpty(configDTO.getToken())) {
                    String token = login(configDTO);
                    if (!StringUtils.isEmpty(token)) {
                        configDTO.setToken(token);
                        log.info("IVS 3800 获取登录成功==============: {}", configDTO);
                        alarmSubscribe(configDTO);
                        intelligenceSubscribe(configDTO);
                    }
                } else {
                    keepAlive(configDTO);
                }
            }
            catch (Exception e) {
                log.error("ivs3800 订阅失败 {}", e.getMessage());
            }
        }
    }

    private static Boolean keepAlive(AlarmIntegrationConfigDTO configDTO) {
        if (StringUtils.isEmpty(configDTO.getIpAndPort())) {
            log.error("3800 配置为空: {}", configDTO);
            return false;
        }
        log.info("3800保活 {}", configDTO);
        String url = configDTO.getIpAndPort() + IVS3800Constant.KEEP_ALIVE_URL;
        if (StringUtils.isEmpty(configDTO.getToken())) {
            log.error("3800 token为空, 保活失败: {}", configDTO);
            return false;
        }
        String result = HttpUtil.createGet(url)
                .cookie("JSESSIONID=" + configDTO.getToken())
                .execute()
                .body();
        log.info("3800 保活请求返回====================》{}", JSONObject.toJSONString(result));
        JSONObject object = JSONObject.parseObject(result);
        if (object.getInteger("resultCode") != 0) {
            configDTO.setToken(null);
            return false;
        }
        log.info("IVS 3800 保活成功 {}", configDTO);
        return true;
    }

    private static String login(AlarmIntegrationConfigDTO configDTO) {
        if (StringUtils.isEmpty(configDTO.getIpAndPort())) {
            log.error("3800 配置为空: {}", configDTO);
            return null;
        }
        log.info("3800登录 {}", configDTO);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userName", configDTO.getLoginName());
        jsonObject.put("password", configDTO.getPassword());
        String url = configDTO.getIpAndPort() + IVS3800Constant.LOGIN_URL;

        HttpResponse response = HttpUtil.createPost(url)
                .body(jsonObject.toString())
                .execute();
        String body = response.body();
        String setCookieHeader = response.header("Set-Cookie");
        String JSESSIONID = null;
        if (Objects.nonNull(setCookieHeader)) {
            JSESSIONID = IVS3800Subscribe.getCookieToken(setCookieHeader);
            if (Objects.isNull(JSESSIONID)) {
                log.error("登录错误 cookies: {}", body);
                return null;
            }
            log.info("3800 获取token成功 {}", JSESSIONID);
            return JSESSIONID;
        } else {
            log.error("3800 登录错误 body: {}", body);
        }
        return null;
    }

    public static List<CameraBriefInfo> getCameraList(AlarmIntegrationConfigDTO configDTO) {
        List<CameraBriefInfo> cameraList = new ArrayList<>();
        int fromIndex = 1;
        int toIndex = 1;
        HuaWei3800DeviceListResult allResult;
        try {
            log.info("当前  fromIndex：{}----toIndex:{}", fromIndex, toIndex);
            HuaWei3800DeviceListResult result = doGetCameraList(configDTO, fromIndex, toIndex);
            // 判断是否请求成功
            if (0 == result.getResultCode()) {
                // 一次性调完，保证设备中台同步时全量新增和全量修改
                int total = result.getCameraBriefInfosV2().getTotal();
                log.info("3800平台拉取设备列表个数:{}", total);

                allResult = doGetCameraList(configDTO, fromIndex, total);
                if (0 == allResult.getResultCode()
                        && allResult.getCameraBriefInfosV2().getCameraBriefInfoList().getCameraBriefInfo().size() == total) {
                    // 将请求结果加入结果集
                    cameraList.addAll(allResult.getCameraBriefInfosV2().getCameraBriefInfoList().getCameraBriefInfo());
                } else {
                    throw new RuntimeException("hw3800 get all devices fail," + result.getResultCode());
                }
            } else {
                throw new RuntimeException("hw3800 first pull devices fail," + result.getResultCode());
            }
        } catch (Exception e) {
            log.error("hw3800 getCameraList error: {}, {}, {}, exception: {}", HuaWei3800DeviceListResult.class, fromIndex, toIndex, e.getMessage());
            return Collections.emptyList();
        }
        // 必须全部拉取才进行同步
        log.info("项目 {} 3800平台设备个数：{}", configDTO.getProjectId(), cameraList.size());

        return cameraList;
    }

    public static HuaWei3800DeviceListResult doGetCameraList(AlarmIntegrationConfigDTO configDTO, int fromIndex, int toIndex) {
        String url = configDTO.getIpAndPort() + IVS3800Constant.DEVICE_LIST_URL;
        String body = HttpUtil.createGet(url)
                .cookie("JSESSIONID=" + configDTO.getToken())
                .form("deviceType", 35)
                .form("fromIndex", fromIndex)
                .form("toIndex", toIndex)
                .setConnectionTimeout(3000)
                .setReadTimeout(5000)
                .execute()
                .body();
        return JSON.parseObject(body, HuaWei3800DeviceListResult.class);
    }

    private void syncConfig() {
        List<AlarmIntegrationConfigDTO> list = alarmIntegrationConfig.getIntegrationProductConfig(
                null, ProductEnum.HUAWEI_IVS3800.getId());
        for (AlarmIntegrationConfigDTO i : list) {
            if (ObjectUtils.isEmpty(i)) {
                log.error("3800 告警集成配置为空，{}", i);
                continue;
            }
            for (AlarmIntegrationConfigDTO j : integrationConfigList) {
                if (Objects.nonNull(j.getToken()) && Objects.equals(j.getRowId(), i.getRowId())) {
                    i.setToken(j.getToken());
                }
            }
        }
        integrationConfigList.clear();
        integrationConfigList.addAll(list);
    }

    public static String getCookieToken(String setCookieHeader) {
        String JSESSIONID = null;
        if (!StringUtils.isEmpty(setCookieHeader)) {
            String[] cookies = setCookieHeader.split(";");
            for (String cookie : cookies) {
                List<String> splits = Arrays.asList(cookie.split("="));
                String cookieKey = Optional.ofNullable(splits.get(0)).map(i -> i.trim()).orElse(null);
                String cookieValue = Optional.ofNullable(splits.get(1)).map(i -> i.trim()).orElse(null);
                if (Objects.nonNull(cookieKey)
                        && Objects.nonNull(cookieValue)
                        && Objects.equals(cookieKey, "JSESSIONID")) {
                    JSESSIONID = cookieValue;
                    break;
                }
            }
        }
        return JSESSIONID;
    }

    public static void alarmSubscribe(AlarmIntegrationConfigDTO configDTO) {
        if (StringUtils.isEmpty(configDTO.getAlarmCallback())) {
            log.info("3800 告警订阅地址为空，{}", configDTO);
            return;
        }

        // 订阅告警,订阅全部设备
        try {
            String subscriberID = "";
            String userResult = HttpRequest.get(configDTO.getIpAndPort() + IVS3800Constant.USERID_URL)
                    .cookie("JSESSIONID=" + configDTO.getToken())
                    .execute()
                    .body();
            log.info("3800 获取用户id请求返回====================》{}", JSONObject.toJSONString(userResult));
            JSONObject userObject = JSONObject.parseObject(userResult);
            if (userObject.getInteger("resultCode") != 0) {
                configDTO.setToken(null);
                log.error("3800 获取用户id 失败");
                return;
            }
            subscriberID = userObject.getString("userId");
            log.info("3800 获取用户id请求成功: {}", subscriberID);

            List<CameraBriefInfo> cameraBriefInfoList = getCameraList(configDTO);
            if (CollectionUtils.isNotEmpty(cameraBriefInfoList)) {
                // 手动添加3800特殊告警设备，这种设备不做同步，切和摄像头需要有对应关系，所以配置添加
                try {
                    List<AlarmIntegrationConfigDTO.AlarmDevicesMap> alarmDevicesMapList = configDTO.getAlarmDevicesMapList();
                    if (CollectionUtils.isNotEmpty(alarmDevicesMapList)) {
                        for (AlarmIntegrationConfigDTO.AlarmDevicesMap alarmDevicesMap: alarmDevicesMapList) {
                            List<AlarmIntegrationConfigDTO.CameraMap> cameraMap = alarmDevicesMap.getCameraMap();
                            if (CollectionUtils.isNotEmpty(cameraMap)) {
                                for (AlarmIntegrationConfigDTO.CameraMap map : cameraMap) {
                                    List<String> sourceCodes = map.getSourceCodes();
                                    if (CollectionUtils.isNotEmpty(sourceCodes)) {
                                        for (String code: sourceCodes) {
                                            if (!StringUtils.isEmpty(code)) {
                                                CameraBriefInfo info = new CameraBriefInfo();
                                                info.setCode(code);
                                                info.setDomainCode(getDomainByCcode(code));
                                                cameraBriefInfoList.add(info);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    log.info("3800 动添加3800特殊告警设备 错误: {}", JSONObject.toJSONString(e));
                }

                List<List<CameraBriefInfo>> sliceList = ListUtils.partition(cameraBriefInfoList, 20);
                for (int i = 0; i < sliceList.size(); i++) {
                    SubscribeContent alarmSubscribeContent = new SubscribeContent();
                    Subscribe alarmSubscribe = new Subscribe();
                    SubscriberInfo subscriberInfo = new SubscriberInfo();
                    subscriberInfo.setSubscriber("1");
                    subscriberInfo.setSubscriberID(subscriberID);
                    alarmSubscribe.setSubscriberInfo(subscriberInfo);
                    AddSubscribeList addSubscribeList = new AddSubscribeList();
                    List<AddSubscribeListContent> subscribeInfo = new ArrayList<>();

                    for (CameraBriefInfo info : sliceList.get(i)) {
                        AddSubscribeListContent addSubscribeListContent = new AddSubscribeListContent();
                        addSubscribeListContent.setAlarmInCode(info.getCode());
                        addSubscribeListContent.setDevDomainCode(info.getDomainCode());
                        addSubscribeListContent.setSubscribeType("1");
                        subscribeInfo.add(addSubscribeListContent);
                    }
                    addSubscribeList.setSubscribeInfo(subscribeInfo);
                    alarmSubscribe.setAddSubscribeList(addSubscribeList);
                    alarmSubscribeContent.setSubscribe(alarmSubscribe);

                    String xml = XMLUtil.convertToXml(alarmSubscribeContent);
                    Pattern p = Pattern.compile("\\s*|\t|\r|\n");
                    Matcher m = p.matcher(xml);
                    String s = m.replaceAll("");
                    HashMap<String, String> body = new HashMap<>();
                    body.put("requestXML", s);
                    log.info("3800 告警订阅请求====================》{}", body);

                    //请求订阅
                    String result = HttpUtil.createPost(configDTO.getIpAndPort() + IVS3800Constant.ALARM_SUBSCRIBE_URL)
                            .body(JSONObject.toJSONString(body))
                            .cookie("JSESSIONID=" + configDTO.getToken())
                            .execute()
                            .body();
                    log.info("3800 告警订阅请求返回====================》{}", result);
                    JSONObject object = JSONObject.parseObject(result);
                    if (object.getInteger("resultCode") != 0) {
                        configDTO.setToken(null);
                        log.error("3800 告警设备订阅请求 失败");
                        return;
                    }
                    log.info("3800 告警订阅请求成功");
                }
            } else {
                log.error("3800 设备为空: {}", configDTO);
            }

            String alarmCallback = configDTO.getAlarmCallback()
                    .replace("{rowId}", configDTO.getRowId().toString());
            String result2 = HttpUtil.createPost(configDTO.getIpAndPort() + IVS3800Constant.REGEDIT_CALLBACK_URL)
                    .body(
                            JSONObject.toJSONString(new HashMap<String, Object>() {{
                                put("wsUri", alarmCallback);
                            }})
                    )
                    .cookie("JSESSIONID=" + configDTO.getToken())
                    .execute()
                    .body();
            log.info("3800 告警注册回调地址返回====================》{}", JSONObject.toJSONString(result2));
            JSONObject object2 = JSONObject.parseObject(result2);
            if (object2.getInteger("resultCode") != 0) {
                configDTO.setToken(null);
                log.error("3800 告警注册回调地址 失败");
                return;
            }
            log.info("3800 告警回调设置成功成功 {}", alarmCallback);
        } catch (Exception e) {
            configDTO.setToken(null);
            log.error("3800 告警订阅 失败: {}，{}", configDTO, e);
        }
    }

    private static String getDomainByCcode(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        int c = code.lastIndexOf("#");
        if (c == -1) {
            return null;
        }
        c++;
        return code.substring(c);
    }

    public static void intelligenceSubscribe(AlarmIntegrationConfigDTO configDTO) {
        if (StringUtils.isEmpty(configDTO.getAlarmCallback())) {
            log.info("3800 智能数据订阅地址为空，{}", configDTO);
            return;
        }

        // 订阅智能数据,订阅全部设备
        String intelligenceCallback = configDTO.getIntelligenceCallback();

        List<CameraBriefInfo> cameraBriefInfoList = getCameraList(configDTO);
        if (CollectionUtils.isEmpty(cameraBriefInfoList)) {
            log.error("查询ivs 3800设备为空");
            return;
        }

        // 查询之前的订阅
        List<IVS3800IntelligenceSubscribeQueryResult.Subscribe> existSubscribedList = new ArrayList<>();
        try {
            // 查询已经订阅智能数据的地址
            String subscribeResult = HttpRequest
                    .get(configDTO.getIpAndPort() + IVS3800Constant.INTELLIGENCE_SUBSCRIBE_URL)
                    .cookie("JSESSIONID=" + configDTO.getToken())
                    .execute()
                    .body();
            // log.info("ivs 3800 查询已经订阅智能数据的地址 结果 ===》{}", subscribeResult);
            IVS3800IntelligenceSubscribeQueryResult result =
                    JSONObject.parseObject(subscribeResult, IVS3800IntelligenceSubscribeQueryResult.class);
            Integer statusCode = Optional.ofNullable(result)
                    .map(i -> i.getResponseStatusObject())
                    .map(i -> i.getStatusCode())
                    .orElse(null);
            if (Objects.equals(statusCode, 0)) {
                log.info("当前没有订阅 ivs 3800 查询已经订阅智能数据 为空");
            } else {
                existSubscribedList = Optional.ofNullable(result)
                        .map(i -> i.getIntelligentSubscribeListObject())
                        .map(i -> i.getIntelligentSubscribeObject())
                        .orElse(null);
                if (CollectionUtils.isNotEmpty(existSubscribedList)) {
                    // 过滤相同的环境的订阅
                    existSubscribedList = existSubscribedList.stream()
                            .filter(i -> Objects.equals(intelligenceCallback, i.getReceiveAddr()))
                            .collect(Collectors.toList());
                } else {
                    throw new DataException("ivs 3800 查询已经订阅智能数据错误");
                }
            }
        } catch (Exception e) {
            log.error("查询ivs 3800已经订阅智能数据的地址错误，{}", e.getMessage());
            throw e;
        }


        // 删除
        try {
            if (CollectionUtils.isNotEmpty(existSubscribedList)) {
                List<String> subscribeIDList = existSubscribedList.stream()
                        .map(IVS3800IntelligenceSubscribeQueryResult.Subscribe::getSubscribeID)
                        .collect(Collectors.toList());
                log.info("3800智能数据 多余订阅id，{}", subscribeIDList);

                // 删除相关订阅
                if (!CollectionUtils.isEmpty(subscribeIDList)) {
                    List<List<String>> sliceList = ListUtils.partition(subscribeIDList, 50);
                    for (int i = 0; i < sliceList.size(); i++) {
                        List<String> list = sliceList.get(i);
                        delIntelligenceSubscribe(configDTO, list);
                    }
                }
            } else {
                log.info("3800 多余订阅已订阅 不存在");
            }
        } catch (Exception e) {
            log.error("删除 ivs 3800多余订阅智能数据错误，{}", e.getMessage());
        }

        // 添加
        try {
            if (CollectionUtils.isNotEmpty(cameraBriefInfoList)) {
                log.info("ivs 3800 订阅请求 当前设备=====》{} , {}", cameraBriefInfoList.size(), cameraBriefInfoList);
                List<List<CameraBriefInfo>> sliceList = ListUtils.partition(cameraBriefInfoList, 10);
                for (int i = 0; i < sliceList.size(); i++) {
                    List<CameraBriefInfo> list = sliceList.get(i);
                    JSONObject obj = getIntelligenceSubscribeBody(list, intelligenceCallback);

                    // log.info("ivs 3800 智能订阅请求体为====================》{}", obj);
                    String result = HttpRequest.post(configDTO.getIpAndPort() + IVS3800Constant.INTELLIGENCE_SUBSCRIBE_URL)
                            .cookie("JSESSIONID=" + configDTO.getToken())
                            .body(JSONObject.toJSONString(obj))
                            .execute()
                            .body();
                    log.info("ivs 3800 智能订阅回调请求返回====================》{}", result);
                }
                log.info("ivs 3800 智能订阅结束 {}", intelligenceCallback);
            } else {
                log.error("智能订阅 ivs 3800 设备为空: {}", configDTO);
            }
        } catch (Exception e) {
            configDTO.setToken(null);
            log.error("ivs 3800 智能订阅失败 {}", e.getMessage());
        }
    }

    private static <T> JSONObject getIntelligenceSubscribeBody(List<T> list, String intelligenceCallback) {
        LocalDateTime begin = DateUtils.getCurrentLocalDateTime().plusHours(-1);
        LocalDateTime end = begin.plusYears(5);
        String beginStr = DateUtils.formatLocalDateTime(begin, "yyyyMMddHHmmss");
        String endStr = DateUtils.formatLocalDateTime(end, "yyyyMMddHHmmss");

        JSONObject obj = new JSONObject();
        JSONObject subscribeListObject = new JSONObject();
        JSONArray subscribeObject = new JSONArray();

        for (int i = 0; i < list.size(); i++) {
            JSONObject subscribe = new JSONObject();
            subscribe.put("ApplicantName", "XHWL3800Subscribes");
            subscribe.put("ApplicantOrg", "HWISV");
            subscribe.put("BeginTime", beginStr);
            subscribe.put("EndTime", endStr);
            subscribe.put("OperateType", 0);
            subscribe.put("ResourceClass", 1);
            subscribe.put("SubscribeDataType", "1");
            subscribe.put("ResultImageDeclare", "00");
            subscribe.put("ResultImageType", "00");
            subscribe.put("DeviceCodeType", "0");
            subscribe.put("ResultFeatureDeclare", 1);
            subscribe.put("SubscribeDetail", "0");
            subscribe.put("Title", "SubscribeIntelligentData");
            subscribe.put("ReceiveAddr", intelligenceCallback);

            T item = list.get(i);
            if (item instanceof CameraBriefInfo) {
                CameraBriefInfo info = (CameraBriefInfo) item;
                subscribe.put("ResourceURI", info.getConnectCode());
            } else if (item instanceof IVS3800IntelligenceSubscribeQueryResult.Subscribe) {
                IVS3800IntelligenceSubscribeQueryResult.Subscribe s = (IVS3800IntelligenceSubscribeQueryResult.Subscribe) item;
                subscribe.put("ResourceURI", s.getResourceURI());
                subscribe.put("SubscribeID", s.getSubscribeID());
            } else {
                break;
            }

            subscribeObject.add(subscribe);
        }
        subscribeListObject.put("SubscribeObject", subscribeObject);
        obj.put("SubscribeListObject", subscribeListObject);
        return obj;
    }

    public static ViidApeSubResult.ApeInfo getViidApeSub(AlarmIntegrationConfigDTO configDTO, String cameraCode) {
        log.info("ivs 3800 查询子设备采集信息: cameraCode: {}", cameraCode);
        String url = configDTO.getIpAndPort()
                + IVS3800Constant.VIID_APE_SUB_URL
                + "?cameraCode=" + cameraCode;
        String body = HttpRequest.get(url)
                .cookie("JSESSIONID=" + configDTO.getToken())
                .execute()
                .body();

        ViidApeSubResult viidApeSubResult = JSONObject.parseObject(body, ViidApeSubResult.class);
        ViidApeSubResult.ApeInfo apeInfo = null;
        log.info("ivs 3800 查询子设备采集信息 结果: {}", viidApeSubResult);
        if (Objects.equals(viidApeSubResult.getResultCode(), 0)) {
            List<ViidApeSubResult.ApeInfo> apeInfos = viidApeSubResult.getApeInfos();
            for (ViidApeSubResult.ApeInfo info: apeInfos) {
                if (Objects.equals(info.getResult(), 0)) {
                    apeInfo = info;
                    break;
                }
            }
        }
        return apeInfo;
    }

    public static void delIntelligenceSubscribe(AlarmIntegrationConfigDTO configDTO, List<String> subscribeIDList) {
        String url = configDTO.getIpAndPort()
                + IVS3800Constant.INTELLIGENCE_SUBSCRIBE_URL
                + "?IDList=" + subscribeIDList.stream().distinct().collect(Collectors.joining(","));

        // log.error("ivs3800删除订阅参数: {}", url);
        String result = HttpRequest.delete(url)
                .cookie("JSESSIONID=" + configDTO.getToken())
                .execute()
                .body();
        JSONObject res = JSONObject.parseObject(result);
        log.info("ivs3800删除订阅 结果: {}", res);
    }

    public static AlarmSnapshotListResult getAlarmSnapshotList(
            AlarmIntegrationConfigDTO configDTO,
            Integer eventId,
            String cameraCode) {
        Map<Object, Object> hashMap = new HashMap<>();
        ArrayList<Object> objects = new ArrayList<>();
        Map<Object, Object> map = new HashMap<>();
        map.put("deviceCode", cameraCode);
        objects.add(map);
        hashMap.put("deviceCodeList", objects);
        Map<Object, Object> maps = new HashMap<>();
        maps.put("alarmEventId", eventId);
        maps.put("alarmInCode", cameraCode);
        hashMap.put("alarmInfo", maps);
        String url = configDTO.getIpAndPort() + IVS3800Constant.ALARM_SNAPSHOT_LIST_URL;
        String token = configDTO.getToken();
        AlarmSnapshotListResult snapshotListResult = null;
        if (!StringUtils.isEmpty(token)) {
            log.info("3800获取告警图片 参数 : {}", hashMap);
            String picture = HttpUtil.createPost(url)
                    .body(JSONObject.toJSONString(hashMap))
                    .cookie("JSESSIONID=" + token)
                    .execute()
                    .body();
            log.info("3800告警图片结果: {}", picture);
            snapshotListResult = JSONObject.parseObject(picture, AlarmSnapshotListResult.class);
        }
        return snapshotListResult;
    }
}
